Skip to content

refactor: removed dead code identified in issue - #848

Open
Arowolokehinde wants to merge 1 commit into
MostroP2P:mainfrom
Arowolokehinde:fix/dead-code-818
Open

refactor: removed dead code identified in issue #848
Arowolokehinde wants to merge 1 commit into
MostroP2P:mainfrom
Arowolokehinde:fix/dead-code-818

Conversation

@Arowolokehinde

@Arowolokehinde Arowolokehinde commented Jul 30, 2026

Copy link
Copy Markdown
  • restore_session: drop unreachable hex-validity guards on PublicKey values; nostr_sdk::PublicKey always serializes to 64-char hex so the guards could never trigger

  • admin_take_dispute: drop is_solver == 0 recheck after find_solver_pubkey; the SQL already filters WHERE is_solver == true so the Ok arm is structurally guaranteed non-zero

  • db: remove rebuild_disputes_table_without_tokens and the SQLite version-fallback branch inside migrate_remove_token_columns; DROP COLUMN is supported on all deployment targets (SQLite >= 3.35 everywhere: Ubuntu 24.04 = 3.45, Debian Bookworm = 3.40, Alpine = 3.43+)

  • dispute: propagate setup_dispute error with map_err(MostroCantDo)? instead of silently swallowing it; the old if .is_ok() pattern skipped order.update() on failure but kept running, leaving the order flags unset while still creating the dispute row

Closes #818

Summary by CodeRabbit

  • Bug Fixes
    • Dispute actions now stop and clearly report setup failures instead of continuing with incomplete processing.
    • Solver authorization handling has been updated for more consistent dispute resolution.
    • Session restoration now proceeds through the restoration workflow without unnecessary early rejection.
    • Legacy dispute data upgrades are more reliable and preserve existing records while removing obsolete fields.

- restore_session: drop unreachable hex-validity guards on PublicKey
  values; nostr_sdk::PublicKey always serializes to 64-char hex so the
  guards could never trigger

- admin_take_dispute: drop is_solver == 0 recheck after
  find_solver_pubkey; the SQL already filters WHERE is_solver == true
  so the Ok arm is structurally guaranteed non-zero

- db: remove rebuild_disputes_table_without_tokens and the SQLite
  version-fallback branch inside migrate_remove_token_columns; DROP
  COLUMN is supported on all deployment targets (SQLite >= 3.35
  everywhere: Ubuntu 24.04 = 3.45, Debian Bookworm = 3.40,
  Alpine = 3.43+)

- dispute: propagate setup_dispute error with map_err(MostroCantDo)?
  instead of silently swallowing it; the old if .is_ok() pattern
  skipped order.update() on failure but kept running, leaving the
  order flags unset while still creating the dispute row
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The pull request removes obsolete validation and fallback branches, propagates dispute setup failures, and replaces legacy disputes-table rebuilding with transactional removal of existing token columns.

Changes

Application and database cleanup

Layer / File(s) Summary
Solver permission gate
src/app/admin_take_dispute.rs
Solver lookup failures reject access without an additional is_solver check.
Restore session entry flow
src/app/restore_session.rs
Restore processing proceeds without local key-format validation.
Dispute setup error propagation
src/app/dispute.rs
setup_dispute failures are returned before subsequent order updates and dispute creation.
Dispute token-column migration
src/db.rs
Existing legacy token columns are dropped transactionally, and the obsolete rebuild-path test is removed.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • MostroP2P/mostro#826: Both changes modify restore-session key validation in src/app/restore_session.rs.

Suggested reviewers: grunch

Poem

I nibbled old branches away,
And watched dispute errors stay.
Tokens dropped in one neat sweep,
Restore keys now flow more deep.
Hop, hop—clean code today!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the PR’s main goal of removing dead code, even though it is a bit generic.
Linked Issues check ✅ Passed The changes address all listed #818 items: restore_session guards, admin_take_dispute recheck, db fallback removal, and setup_dispute error propagation.
Out of Scope Changes check ✅ Passed The diff stays within the dead-code cleanup and error-handling scope described by #818.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/db.rs (1)

3410-3416: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a positive-path migration test.

With rebuild_disputes_table_preserves_rows gone, the only remaining coverage is the no-op branch — the actual drop path (and row preservation) is untested. A test that adds the legacy columns back, inserts a row, runs the migration, and asserts both columns are gone while the row survives would keep coverage on the reachable logic this PR is consolidating onto.

🧪 Sketch of the missing test
#[tokio::test]
async fn migrate_remove_token_columns_drops_legacy_columns_and_preserves_rows() {
    let pool = migrated_pool().await;
    sqlx::query("ALTER TABLE disputes ADD COLUMN buyer_token INTEGER")
        .execute(&pool)
        .await
        .unwrap();
    sqlx::query("ALTER TABLE disputes ADD COLUMN seller_token INTEGER")
        .execute(&pool)
        .await
        .unwrap();
    // insert a dispute row here, then:
    migrate_remove_token_columns(&pool).await.unwrap();
    assert!(!table_column_exists(&pool, "disputes", "buyer_token").await.unwrap());
    assert!(!table_column_exists(&pool, "disputes", "seller_token").await.unwrap());
    // assert the inserted row is still present
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/db.rs` around lines 3410 - 3416, Add a positive-path test alongside
migrate_remove_token_columns_is_noop_without_token_columns that restores both
legacy token columns, inserts a disputes row, runs migrate_remove_token_columns,
and verifies buyer_token and seller_token are removed while the inserted row
remains.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/db.rs`:
- Around line 3410-3416: Add a positive-path test alongside
migrate_remove_token_columns_is_noop_without_token_columns that restores both
legacy token columns, inserts a disputes row, runs migrate_remove_token_columns,
and verifies buyer_token and seller_token are removed while the inserted row
remains.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 46a3b8f6-0bd3-4fdf-b711-402423c284ff

📥 Commits

Reviewing files that changed from the base of the PR and between 94e736a and 9fc0299.

📒 Files selected for processing (4)
  • src/app/admin_take_dispute.rs
  • src/app/dispute.rs
  • src/app/restore_session.rs
  • src/db.rs
💤 Files with no reviewable changes (1)
  • src/app/restore_session.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[LOW] Dead code: unreachable hex guards, is_solver==0 recheck, SQLite rebuild fallback, swallowed setup_dispute error

1 participant